#include "TestListener.h"



TestListener::~TestListener(void)
{
}

bool TestListener::frameRenderingQueued(const Ogre::FrameEvent& evt)
{
	if(mWindow->isClosed())
		return false;

	if(mShutDown)
		return false;

	//Need to capture/update each device
	mKeyboard->capture();
	mMouse->capture();
	return true;
}



//-------------------------------------------------------------------------------------
bool TestListener::keyPressed( const OIS::KeyEvent &arg )

{

	if(arg.key==OIS::KC_ESCAPE){
		mShutDown =true;
	}

	else if(arg.key==OIS::KC_K){

		l->setVisible(!l->isVisible());

	}
	return true;
}

bool TestListener::keyReleased( const OIS::KeyEvent &arg )
{
	//mCameraMan->injectKeyUp(arg);
	return true;
}

//Adjust mouse clipping area
void TestListener::windowResized(Ogre::RenderWindow* rw)
{
	unsigned int width, height, depth;
	int left, top;
	rw->getMetrics(width, height, depth, left, top);

	const OIS::MouseState &ms = mMouse->getMouseState();
	ms.width = width;
	ms.height = height;
}

//Unattach OIS before window shutdown (very important under Linux)
void TestListener::windowClosed(Ogre::RenderWindow* rw)
{
	//Only close for window that created OIS (the main window in these demos)
	if( rw == mWindow )
	{
		if( mInputManager )
		{
			mInputManager->destroyInputObject( mMouse );
			mInputManager->destroyInputObject( mKeyboard );

			OIS::InputManager::destroyInputSystem(mInputManager);
			mInputManager = 0;
		}
	}
}
